﻿@model SiteModel

@{
	ViewBag.Title = "Site Detail";
}

<div style="display: none">
	<div id="formPrettyValidationSummary">
		@Html.ValidationSummary(true, "")
	</div>
</div>

<fieldset style="width: 550px;">
	<legend>
		<label>
			Site Information
		</label>
	</legend>
	<table style="width: 99%;">
		<tr>
			<td class="tablecaption" style="width: 160px;">
				Site ID
			</td>
			<td>
				<div style="padding: 5px; padding-left: 10px; width: 275px;" class=" ui-widget-content ui-corner-all ">
					@Model.Site.SiteID
				</div>
			</td>
		</tr>
		<tr>
			<td class="tablecaption">
				Site URL
			</td>
			<td>
				@Model.Site.MainURL
			</td>
		</tr>
		<tr>
			<td class="tablecaption">
				Site Name
			</td>
			<td>
				@Model.Site.SiteName
			</td>
		</tr>
		<tr>
			<td class="tablecaption">
				Site Tagline
			</td>
			<td>
				@Model.Site.SiteTagline
			</td>
		</tr>
	</table>
</fieldset>

<div id="pnlUsers">
	<table>
		<tr>
			<td>
				@using (Html.BeginForm("SiteRemoveUsers", RouteConfig.AdminCtrlr)) {
					@Html.AntiForgeryToken()
					@Html.HiddenFor(model => model.Site.SiteID)
					@Html.HiddenFor(model => model.Site.SiteName)
					@Html.HiddenFor(model => model.Site.SiteTagline)
					@Html.HiddenFor(model => model.Site.MainURL)

					<fieldset style="width: 450px;">
						<legend>
							<label>
								Users @Html.Partial("_displayErrorPopupButton")
							</label>
						</legend>
						<br />
						<div>

							@{
					var grid = CarrotWeb.CarrotWebGrid<UserModel>(Model.Users);

					grid.TableAttributes = new { @class = "datatable" };
					grid.THeadAttributes = new { @class = "tablehead" };
					grid.EmptyDataTemplate = @<text><p> <b>No records found.</b> </p></text>;
					grid.UseDataPage = false;
					grid.ConfigName(Html.NameFor(x => x.Users));

					grid
					.AddColumn(new CarrotGridTemplateColumn<UserModel> {
						HasHeadingText = false,
						FormatTemplate = @<text> @grid.FormFieldFor(m => m.Selected, GridFormFieldType.Checkbox)
						@grid.FormFieldFor(m => m.User.UserName, GridFormFieldType.Hidden)
						@grid.FormFieldFor(m => m.User.UserKey, GridFormFieldType.Hidden)
						@grid.FormFieldFor(m => m.User.UserId, GridFormFieldType.Hidden)
						@grid.FormFieldFor(m => m.User.Email, GridFormFieldType.Hidden)
						@grid.FormFieldFor(m => m.User.IsAdmin, GridFormFieldType.Hidden)
						@grid.FormFieldFor(m => m.User.IsEditor, GridFormFieldType.Hidden)
						@grid.FormFieldFor(m => m.User.FullName_FirstLast, GridFormFieldType.Hidden)</text>
					})
						.AddColumn(x => x.User.UserName, new CarrotGridColumn())
						.AddColumn(x => x.User.FullName_FirstLast, new CarrotGridColumn())
						.AddColumn(x => x.User.Email, new CarrotGridColumn())
						.AddColumn(x => x.User.IsAdmin, new CarrotGridBooleanImageColumn {
							ImagePathTrue = "~/Assets/Admin/Images/lightbulb.png",
							ImagePathFalse = "~/Assets/Admin/Images/lightbulb_off.png"
						})
						.AddColumn(x => x.User.IsEditor, new CarrotGridBooleanImageColumn {
							ImagePathTrue = "~/Assets/Admin/Images/lightbulb.png",
							ImagePathFalse = "~/Assets/Admin/Images/lightbulb_off.png"
						});

						@grid.OutputHtmlBody()

							}
						</div>

						@if (Model.Users.Any()) {
							<br />
							<p>
								<input type="submit" name="btnRemove" value="Remove Selected" id="btnRemove" />
							</p>
						}
					</fieldset>

				}
			</td>
			<td>
				&nbsp;&nbsp;&nbsp;
			</td>
			<td>
				@using (Html.BeginForm("SiteAddUser", RouteConfig.AdminCtrlr)) {
					@Html.AntiForgeryToken()
					@Html.HiddenFor(model => model.Site.SiteID)
					@Html.HiddenFor(model => model.Site.SiteName)
					@Html.HiddenFor(model => model.Site.SiteTagline)
					@Html.HiddenFor(model => model.Site.MainURL)

					<fieldset style="width: 400px;">
						<legend>
							<label>
								Add Users @Html.Partial("_displayErrorPopupButton")
							</label>
						</legend>

						<script src="~/Assets/Admin/Includes/FindUsers.js" type="text/javascript"></script>
						<script type="text/javascript">
							$(document).ready(function () {
								initFindUsers("@Html.IdFor(m => m.NewUserId)", "txtSearch");
							});
						</script>

						<div style="width: 400px;">
							<p>
								Search for users to add to this group. Search by either username or email address.
							</p>
							<p>
								<b>Search:</b> <span id="spanResults"></span><br />
								<input name="txtSearch" type="text" maxlength="100" id="txtSearch" class="form-control-lg" />
								@Html.ValidationMessageFor(m => m.NewUserId, "", new { @class = "validationError" })
								@Html.HiddenFor(m => m.NewUserId)
							</p>
							<p>
								@Html.CheckBoxFor(m => m.NewUserAsEditor)
								@Html.LabelFor(m => m.NewUserAsEditor)
							</p>
							<p style="text-align: right;">
								<input type="submit" name="btnAddUsers" value="Add User" id="btnAddUsers" />
							</p>
						</div>
					</fieldset>
				}
			</td>
		</tr>
	</table>
</div>

<script type="text/javascript">
	$(document).ready(function () {
		cmsInputEnterBlock();
	});
</script>